from threading import Thread, Lock


num = 0

def thread_lock(l):
    global num
    for i in range(10**6):
        with l:
            num += i
            num -= i


if __name__ == "__main__":
    lock = Lock()
    arr = []
    for _ in range(3):
        lock_thread = Thread(target=thread_lock, args=(lock,))
        lock_thread.start()
        arr.append(lock_thread)
    for t in arr:
        t.join()
    print(num)